﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using CharacterCreation.Business.Calculations;
using CharacterCreation.Business.Repositories;

namespace CharacterCreation.Business.ViewModels
{
    public class VMCharacterStatistic : ViewModelBase
    {
        public Guid CharacterId { get; set; }
        public int OrderIndex { get; set; }

        public string Name { get; set; }
        public string Description { get; set; }
        public int RolledValue { get; set; }
        public int MovedValue { get; set; }
        public int RaceBonus { get; set; }

        public int TotalXP { get; set; }

        public int Total { get; set; }
        public string Information { get; set; }

        public List<VMCharacterStatisticXPDetail> XPDetails { get; set; }

        public void Update()
        {
            this.TotalXP = this.Load(c => c.XPDetails).Sum(x => x.XP);
            this.Total = LevelCalculations.CalculateStatistic(this.RolledValue + this.MovedValue, this.TotalXP) + this.RaceBonus;
            this.Information = StatisticRepository.GetStatisticValue(this.Name, this.Total);
            RepositoryFactory.Create<VMCharacterStatistic>().Update(this);
        }
    }
}
